package may.qf.util;

import java.text.SimpleDateFormat;

public class StringUtil {

    public static Integer stringToInteger(String s){
        return Integer.parseInt(s);
    }

    public static Double stringToDouble(String s){
        return Double.parseDouble(s);
    }

    private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * util 转 sql
     */
    public static java.sql.Date utilToSql(java.util.Date date) {
        return new java.sql.Date(date.getTime());
    }

    /**
     * 字符串转util
     */
    public static java.util.Date stringToUtil(String str) {
        try {
            return SDF.parse(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * util转字符串
     */
    private static String utilToString(java.util.Date date) {
        return SDF.format(date);
    }


    public static Integer stringToInt(String val) {
        int i = 0;
        try {
            i = isNotEmpty(val) ? Integer.parseInt(val) : -1;
        } catch (NumberFormatException e) {
            e.printStackTrace();
            // 设置如果出现异常, 即字符串不是数值,给一个默认值出去
            i = -1;
        }
        return i;
    }
    public static boolean isNotEmpty(String... strs) {
        for (String str : strs) {
            if (str == null || str.trim().length() == 0) {
                return false;
            }
        }
        return true;
    }
}
